package com.kk.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kk.mapper.SysOperationLogMapper;
import com.kk.pojo.entity.SysOperationLog;
import com.kk.service.SysOperationLogService;
import com.kk.utils.VirtualThreadUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 操作日志Service实现类
 *
 * @author kk
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog>
        implements SysOperationLogService {

    @Override
    public void recordOperationLog(SysOperationLog operationLog) {
        // 使用虚拟线程异步记录日志
        VirtualThreadUtil.runAsync(() -> {
            try {
                this.save(operationLog);
                log.debug("操作日志记录成功: {} - {}",
                        operationLog.getUsername(), operationLog.getDescription());
            } catch (Exception e) {
                log.error("操作日志记录失败", e);
            }
        });
    }
}